//
//  MyAdViewModel.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/22/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit

typealias MyAdInfoCellConfigurator = TableCellConfigurator<MyAdInfoCell, MyAdViewModel.MyAdInfoData?>
typealias MyAdActionsCellConfigurator = TableCellConfigurator<MyAdActionsCell, MyAdViewModel.MyAdEditItem?>
typealias MyAdSwitchCellConfigurator = TableCellConfigurator<MyAdSwitchCell, MyAdViewModel.MyAdSwitchData?>
typealias MyAdComboCellConfigurator = TableCellConfigurator<MyAdComboCell, MyAdViewModel.Combo?>


final class MyAdViewModel {
    
    struct MyAdInfoData {
        var leftDays: String
        var countTxt: String
    }
    
    struct MyAdSwitchData {
        var text: String
        var price: Int
        var isSelected: Bool = false
        var icon: UIImage?
        var type: SwitchType
    }
    
    struct MyAdEditItem {
        var isPaused: Bool
    }
    
    enum SwitchType {
        case top, searchUp, colored, special
    }
    
    struct Combo {
        var name: String
        var description: String
        var price: Int
        var options: PostReklama
    }
    
    var items: [CellConfigurator] = []
    private var postModel: PostModel!
    let backendService = Backend()
    
    var initialMarketing: [MyAdSwitchData] = [
        MyAdSwitchData(text: "Авто поднятие в ТОП", price: 799, icon: UIImage(named: "top"), type: .top),
        MyAdSwitchData(text: "Авто поднятие в поиске", price: 199, icon: UIImage(named: "top"), type: .searchUp),
        MyAdSwitchData(text: "Выделение", price: 499, icon: UIImage(named: "paint"), type: .colored),
        MyAdSwitchData(text: "Спецпредложение", price: 1990, icon: UIImage(named: "safe"), type: .special)
    ]
    
    private let comboDetails: [Combo] = [
        Combo(name: "VIP", description: "Все опции на месяц", price: 9900, options: PostReklama(isTop: true, searchUp: true, special: true, colored: true)),
        Combo(name: "Turbo", description: "3 опции на неделю", price: 2990, options: PostReklama(isTop: true, special: true, colored: true))
    ]
    
    
    
    public func setUpCells (advert: Post) {
        self.postModel = PostModel(post: advert)
        
        let editItem = MyAdEditItem(isPaused: advert.status == .archived)
        
        let _items: [CellConfigurator] = [
            CarHeaderCellConfigurator(item: MainViewModel.CarHeader(postModel: PostModel(post: advert))),
            MyAdInfoCellConfigurator(item: MyAdInfoData(leftDays: postModel.leftDaysText, countTxt: postModel.visCount)),
            MyAdActionsCellConfigurator(item: editItem)
        ]
        
        // TODO: UPADTE IN NEXT VERSION
        
//        for item in initialMarketing {
//            _items.append(MyAdSwitchCellConfigurator(item: item))
//        }
//
//        for combo in comboDetails {
//            _items.append(MyAdComboCellConfigurator(item: combo))
//        }
        items = _items
    }
}
